package com.xy.biz.fd.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.biz.fd.domain.bo.DocumentBO;
import com.xy.biz.fd.domain.po.DocumentPO;
import com.xy.biz.fd.domain.query.DocumentQuery;
import com.xy.biz.fd.domain.req.document.CopyDocumentRequest;
import com.xy.biz.fd.domain.req.document.CreateDocumentRequest;
import com.xy.biz.fd.domain.resp.GetDocumentResponse;
import com.xy.biz.fd.domain.req.document.SaveDocumentRequest;
import com.xy.biz.fd.domain.req.document.ListDocumentRequest;
import com.xy.biz.fd.domain.resp.GetEditorInfoResponse;
import com.xy.biz.fd.domain.resp.ListDocumentModifyInfoResponse;
import com.xy.tool.minio.domain.minio.obj.FileModel;
import com.xy.tool.util.BeanUtilsEx;

/**
 *
 *
 * @author ssl
 * @date 2021-1-23
 */
public class DocumentConverter {

    public static DocumentPO toPO(DocumentBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentPO(), true);
    }

    public static List<DocumentPO> toPO(Collection<DocumentBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new DocumentPO(), true);
    }

    public static DocumentBO fromPO(DocumentPO source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentBO());
    }

    public static List<DocumentBO> fromPO(Collection<DocumentPO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new DocumentBO());
    }

    public static List<DocumentBO> fromResponse(Collection<GetDocumentResponse> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new DocumentBO(), true);
    }

    public static DocumentBO toBO(SaveDocumentRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentBO(), true);
    }

    public static DocumentBO toBO(CreateDocumentRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentBO(), true);
    }

    public static DocumentBO toBO(CopyDocumentRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentBO(), true);
    }

    public static List<DocumentBO> toBO(Collection<SaveDocumentRequest> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new DocumentBO(), true);
    }

    public static GetDocumentResponse toResponse(DocumentBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GetDocumentResponse());
    }

    public static GetDocumentResponse toResponse(DocumentPO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GetDocumentResponse());
    }

    public static GetEditorInfoResponse getEditorInfoResponse(FileModel source) {
        return BeanUtilsEx.copyProperties(source, () -> new GetEditorInfoResponse());
    }

    public static List<GetDocumentResponse> toResponse(Collection<DocumentBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetDocumentResponse());
    }

    public static DocumentQuery toQuery(ListDocumentRequest source) {
        if (null == source) {
            return null;
        }
        DocumentQuery target = new DocumentQuery(source.getPageIndex(), source.getPageSize());
        BeanUtilsEx.copyProperties(source, target);
        return target;
    }

    public static DocumentQuery toQuery(SaveDocumentRequest source) {
        if (null == source) {
            return null;
        }
        return BeanUtilsEx.copyProperties(source, () -> new DocumentQuery());
    }

    public static List<ListDocumentModifyInfoResponse> toListDocumentModifyInfoResponse(Collection<DocumentBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ListDocumentModifyInfoResponse());
    }

}
